
#if	!defined( __20081023_DEF_SMARTPTR_H__ )
#define	__20081023_DEF_SMARTPTR_H__

#include	<assert.h>

namespace PCE_Lib {
namespace CEnv_Def {
namespace PCE_Lib_CurrentCEnvironment {
namespace Tools {

	template< typename T > class SmartPtr
	{
	public:
		T & operator*( void ) throw()
		{
			assert( NotNull( m_Ptr ) );
			return *m_Ptr;
		}
		const T & operator*( void ) const throw()
		{
			assert( NotNull( m_Ptr ) );
			return *m_Ptr;
		}
		T * operator->( void ) throw()
		{
			assert( NotNull( m_Ptr ) );
			return m_Ptr;
		}
		const T * operator->( void ) const throw()
		{
			assert( NotNull( m_Ptr ) );
			return m_Ptr;
		}
		T * operator= ( const T * ptr ) throw()
		{
			m_Ptr = const_cast< T * >( ptr );
			return m_Ptr;
		}
		operator T * ( void ) throw() { return m_Ptr; }
		operator const T * ( void ) const throw() { return ( const T * ) m_Ptr; }
	public:
		T * Get( void ) throw() { return m_Ptr; }
		const T * Get( void ) const throw() { return m_Ptr; }
		T * Release( void ) throw()
		{
			T	* tmp = m_Ptr;
			SetNull( m_Ptr );
			return tmp;
		}
	public:
		SmartPtr( void ) throw() : m_Ptr() {}
		explicit SmartPtr( T * ptr ) throw() : m_Ptr( ptr ) {}
		~SmartPtr( void ) throw()
		{
			if( NotNull( m_Ptr ) ) {
				delete m_Ptr;
			}
		}
	protected:
		T	* m_Ptr;
	};

	template< typename T > class SmartVPtr
	{
	public:
		T & operator[]( ssize_t pos ) throw()
		{
			assert( NotNull( m_Ptr ) );
			return m_Ptr[ pos ];
		}
		T & operator[]( usize_t pos ) throw()
		{
			assert( NotNull( m_Ptr ) );
			return m_Ptr[ pos ];
		}
		const T & operator[]( ssize_t pos ) const throw()
		{
			assert( NotNull( m_Ptr ) );
			return m_Ptr[ pos ];
		}
		const T & operator[]( usize_t pos ) const throw()
		{
			assert( NotNull( m_Ptr ) );
			return m_Ptr[ pos ];
		}
		T * operator= ( const T * ptr ) throw()
		{
			m_Ptr = const_cast< T * >( ptr );
			return m_Ptr;
		}
		operator T * ( void ) throw() { return m_Ptr; }
		operator const T * ( void ) const throw() { return ( const T * ) m_Ptr; }
	public:
		T * Get( void ) throw() { return m_Ptr; }
		const T * Get( void ) const throw() { return m_Ptr; }
		T * Release( void ) throw()
		{
			T	* tmp = m_Ptr;
			SetNull( m_Ptr );
			return tmp;
		}
	public:
		SmartVPtr( void ) throw() : m_Ptr() {}
		explicit SmartVPtr( T * ptr ) throw() : m_Ptr( ptr ) {}
		~SmartVPtr( void ) throw()
		{
			if( NotNull( m_Ptr ) ) {
				delete [] m_Ptr;
			}
		}
	protected:
		T	* m_Ptr;
	};

}	// Tools
}	// PCE_Lib_CurrentCEnvironment
}	// CEnv_Def
}	// PCE_Lib

#endif	// __20081023_DEF_SMARTPTR_H__
